//
//  JSBaseTableViewCell.m
//  NiubilityProject
//
//  Created by Apple on 2018/3/29.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import "JSBaseTableViewCell.h"

@implementation JSBaseTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self js_setupCell];
        
        [self js_buildSubview];
    }
    return self;
}
- (void)js_setupCell{
    
}

- (void)js_buildSubview{
    
}

- (void)js_loadContent{
    
}
+ (JSCellDataAdapter *)js_dataAdapterWithCellReuseIdentifier:(NSString *)reuseIdentifier
                                                        data:(id)data
                                                  cellHeight:(CGFloat)height
                                                        type:(NSInteger)type
{
    NSString *tmpReuseIdentifier = reuseIdentifier.length <= 0? NSStringFromClass([self class]) : reuseIdentifier;
    return [JSCellDataAdapter js_cellDataAdapterWithCellReuseIdentifier:tmpReuseIdentifier data:data cellHeight:height cellType:type];
}

- (void)js_setWeakReferenceWithCellDataAdapter:(JSCellDataAdapter *)dataAdapter
                                          data:(id)data
                                     indexPath:(NSIndexPath *)indexPath
                                     tableView:(UITableView *)tableView
{
    _dataAdapter = dataAdapter;
    _data        = data;
    _indexPath   = indexPath;
    _tableView   = tableView;
}
- (void)js_updateWithNewCellHeight:(CGFloat)height
                          animated:(BOOL)animated
{
    if (self.tableView && self.dataAdapter)
    {
        if (animated)
        {
            self.dataAdapter.cellHeight = height;
            [self.tableView beginUpdates];
            [self.tableView endUpdates];
            
        }
        else
        {
            self.dataAdapter.cellHeight = height;
            [self.tableView reloadData];
        }
        
    }
    
}

@end
